/*
 * GuildFraktionInfo - list the reputation and the guild level of all members of a wow guild
 * Copyright (C) [2012 - 2013] [www.marantis.de]
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 
 * License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later 
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program; if not, 
 * see <http://www.gnu.org/licenses/>.
 */
package de.marantis.app.wow.gfi.beans;

import java.io.Serializable;

import de.marantis.app.wow.gfi.helper.ArmoryReputationHelper;
import de.marantis.app.wow.gfi.helper.ReputationEnum;

public class ReputationBean implements Comparable<ReputationBean>,Serializable {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ReputationEnum rep;
    private int score;

    public ReputationBean(){
        this.rep = ReputationEnum.getNewWithInt(0);
        this.score = 0;
    }
    
    public ReputationEnum getReputation() {
        return rep;
    }

    public void setReputation(ReputationEnum rep) {
        this.rep = rep;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 53 * hash + (this.rep != null ? this.rep.hashCode() : 0);
        hash = 53 * hash + this.score;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ReputationBean other = (ReputationBean) obj;
        if (this.rep != other.rep) {
            return false;
        }
        if (this.score != other.score) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {

        String reputationText = ArmoryReputationHelper.getReputationText_DE(this.rep);
        
        StringBuffer sb = new StringBuffer("");
        sb.append(reputationText);

        if (this.rep.equals(ReputationEnum.undefined)){
            return sb.toString();
        }
        
        String scoreLevelText = ArmoryReputationHelper.getReputationScoreLevelText(this.score, this.rep);

        sb.append(" (");
        sb.append(scoreLevelText);
        sb.append(")");
        return sb.toString();
    }

    @Override
    public int compareTo(ReputationBean repBean) {

        int thisValue = this.rep.getRep();
        int otherValue = repBean.getReputation().getRep();
            
        if (thisValue < otherValue) {
            return -1;
        } else if (thisValue > otherValue) {
            return 1;
        } else {
            if (this.score < repBean.score) {
                return -1;
            } else if (this.score > repBean.score) {
                return 1;
            } else {
                return 0;
            }
        }
    }
}
